package model.handler.fileHandling;

import java.io.File;
import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import model.Configuration;
import de.nixosoft.jlr.JLRGenerator;

/**
 * Utility class handling the creation of .pdf files out of .tex files.
 * @author Matthias Haupt
 *
 */
public final class PdfHandler {
	
	private static Logger log = LogManager.getLogger("ERROR");
	private static Logger debug = LogManager.getLogger("DEBUG");
	
	private PdfHandler(){
		throw new AssertionError("PdfHandler musn't be instantiated!");
	}

	public static File createPdf(File texFile){
		JLRGenerator pdfGen = new JLRGenerator();
		pdfGen.deleteTempFiles(false, true, true);
		try {
			if (!pdfGen.generate(texFile, new File(Configuration.PATHTEXINVOICECUSTOMER), new File(Configuration.PATHTOTEX))) { 
				debug.debug(pdfGen.getErrorMessage());
			}
			return pdfGen.getPDF();
		} catch (IOException e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return null;
	}
}
